﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{

    public class WarpMasterData : BaseFunction
    {


        public WarpMasterData()
            : base()
        {

        }
        public WarpMasterData(OracleConnection _OracleDB, IntexReptServBLClient _proxy)
            : base(_OracleDB, _proxy)
        {

        } 
        public WarpMasterData(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }
        public DataSet GetWarpMaster(DataRow dwBSFARB)
        {
            DataSet setResult = new DataSet();
            DataSet setReturn = new DataSet();
            OracleCommand or1;
            try
            { 
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT *FROM INTEX.BSSATZ WHERE BSKART = :ArticleNum";
                or1.Parameters.Add("ArticleNum", OracleType.NVarChar).Value = dwBSFARB["BSFKART"].ToString();
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "BSSATZ";
                }
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet GetWarpColorWay(DataRow dwBSFARB)
        {
            DataSet setResult = new DataSet();
            DataSet setReturn = new DataSet();
            OracleCommand or1;
            try
            {
                or1 = OracleDB.CreateCommand();
                #region Color
                or1.CommandText = "SELECT* FROM INTEX.BSFARB WHERE BSFKART = :ArticleNum AND BSFKVAR=:ArticleVar"
                +" AND BSFKFARBE=:ArticleColor";
                or1.Parameters.Add("ArticleNum", OracleType.NVarChar).Value = dwBSFARB["BSFKART"].ToString();
                or1.Parameters.Add("ArticleVar", OracleType.NVarChar).Value = dwBSFARB["BSFKVAR"].ToString();
                or1.Parameters.Add("ArticleColor", OracleType.NVarChar).Value = dwBSFARB["BSFKFARBE"].ToString();
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "BSFARB"; 
                }
                #endregion 
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
      
        }
        public DataSet GetTechnicalData(DataRow dwBSFARB)
        {
            DataSet setResult = new DataSet();
            DataSet setReturn = new DataSet();
            OracleCommand or1;
            try
            {
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT * WHERE BHKART = :ArticleNum AND BHKVAR=:ArticleVar";
                or1.Parameters.Add("ArticleNum", OracleType.NVarChar).Value = dwBSFARB["BSFKART"].ToString();
                or1.Parameters.Add("ArticleVar", OracleType.NVarChar).Value = dwBSFARB["BSFKVAR"].ToString();
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "BHSATZ";
                }
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet GetWarpBeamBS09(DataRow dwBSFARB)
        {
            DataSet setResult = new DataSet();
            DataSet setReturn = new DataSet();
            OracleCommand or1;
            try
            {
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT * FROM INTEX.BASTKE WHERE BAKART = :ArticleNum AND BAKVAR=:ArticleVar"
                +" AND BAKFARBE=:ArticleColor";
                or1.Parameters.Add("ArticleNum", OracleType.NVarChar).Value = dwBSFARB["BSFKART"].ToString();
                or1.Parameters.Add("ArticleVar", OracleType.NVarChar).Value = dwBSFARB["BSFKVAR"].ToString();
                or1.Parameters.Add("ArticleColor", OracleType.NVarChar).Value = dwBSFARB["BSFKFARBE"].ToString();
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "BASTKE";
                }
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet GetWarpYarn(DataRow dwBSFARB)
        {
            DataSet setResult = new DataSet();
            DataSet setReturn = new DataSet();
            OracleCommand or1;
            try
            {
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT * FROM INTEX.BASTGA WHERE BAGART = :ArticleNum AND BAGVAR=:ArticleVar";
                //AND BAGFARBE=:ArticleColor";
                or1.Parameters.Add("ArticleNum", OracleType.NVarChar).Value = dwBSFARB["BSFKART"].ToString();
                or1.Parameters.Add("ArticleVar", OracleType.NVarChar).Value = dwBSFARB["BSFKVAR"].ToString();
                //or1.Parameters.Add("ArticleColor", OracleType.NVarChar).Value = dwBSFARB["BSFKFARBE"].ToString();
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "BASTGA";
                }
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
        public DataSet GetBeamTypeBS31(DataRow dwBSFARB)
        {
            DataSet setResult = new DataSet();
            DataSet setReturn = new DataSet();
            OracleCommand or1;
            try
            {
                or1 = OracleDB.CreateCommand();
                or1.CommandText = "SELECT * FROM INTEX.BSGROE WHERE RowNum<2 and BSGART = :ArticleNum";
                or1.Parameters.Add("ArticleNum", OracleType.NVarChar).Value = dwBSFARB["BSFKART"].ToString();
                setResult = Connect2Proxy(or1);
                if (setResult.Tables.Count > 0)
                {
                    setResult.Tables[0].TableName = "BSGROE";

                }
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }

        public DataSet BuildWarpMasterData(DataRow dwBSFARB)
        {
            DataSet setResult = new DataSet();
            DataSet setReturn = new DataSet();
            try
            {
                setResult = GetWarpMaster(dwBSFARB);
                setReturn.Merge(setResult);
                setResult = GetWarpColorWay(dwBSFARB);
                setReturn.Merge(setResult);
                setResult = GetTechnicalData(dwBSFARB);
                setReturn.Merge(setResult);
                setResult = GetBeamTypeBS31(dwBSFARB);
                setReturn.Merge(setResult);
                setResult = GetWarpBeamBS09(dwBSFARB);
                setReturn.Merge(setResult);
                setResult = GetWarpYarn(dwBSFARB);
                setReturn.Merge(setResult);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
    }
}